#include "myplane.h"
#include"config.h"
myplane::myplane() {
    //初始化飞机图片
    m_plane.load(MYPLANE_PATH);
    //飞机坐标
    m_x=(GAME_WIDTH-m_plane.width())*0.5;
    m_y=(GAME_HEIGHT-m_plane.height());
    //初始化边框
    m_Rect.setWidth(m_plane.width());
    m_Rect.setHeight(m_plane.height());
}

void myplane::shoot()
{
    //累积时间间隔
    m_recorder++;
    //未达到间隔
    int a=BULLET__MY_INTEVal ;
    if(m_recorder<BULLET__MY_INTEVal){
        return;
    }
    m_recorder=0;

    //发射子弹*************//三行
    for (int row = 0; row < 3; ++row) {
        for (int i = 0; i < BULLET_MY_NUM; ++i) {
            if (m_bullets[i].m_Free) {
                // 如果空闲，发射
                m_bullets[i].m_Free = false;
                // 设置子弹坐标
                m_bullets[i].m_X = m_x + m_Rect.width() * 0.5+(row-1) * m_bulletSpacing;
                // 根据行数调整子弹的Y坐标
                m_bullets[i].m_Y = m_y ;
                break;
            }
        }
    }
}

    ///////


void myplane::setPosition(int x, int y)
{
    m_x=x;
    m_y=y;
    m_Rect.moveTo(m_x,m_y);
}
